package cn.tedu.qxhouserent.commons.web;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class JsonResult<T> implements Serializable {
    private Integer state;
    private String message;
    private T data;

    public static JsonResult<Void> ok(){
        return ok(null);
    }

    public static <T> JsonResult <T> ok(T data){
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setState(ServiceCode.OK.getValue());
        jsonResult.setData(data);
        return jsonResult;
    }

    public static JsonResult fail(ServiceCode serviceCode ,String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setState(serviceCode.getValue());
        jsonResult.setMessage(message);
        return jsonResult;

    }
}
